package ua.khuta.myskidka;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class mySCadapter extends SimpleCursorAdapter {
	LayoutInflater inflater;
	Context cont;

	@SuppressWarnings("deprecation")
	public mySCadapter(Context context, int layout, Cursor c, String[] from,
			int[] to) {
		
		super(context, layout, c, from, to);
		inflater = LayoutInflater.from(context);
		cont = context;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View row = convertView;
		ViewHolder holder;

		if (convertView == null) {
			row = inflater.inflate(R.layout.item_news, parent, false);
			holder = new ViewHolder();
			holder.imageView1 = (ImageView) row
					.findViewById(R.id.item_news_iv_image);
			holder.textView1 = (TextView) row
					.findViewById(R.id.item_news_tv_title);
			holder.textView2 = (TextView) row
					.findViewById(R.id.item_news_tv_short_description);

			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}

		// ImageView image = (ImageView) v.findViewById(R.id.iv_place_logo);
		// TextView tv1= (TextView)v.findViewById( R.id.tv_place_name);
		// TextView tv2= (TextView)v.findViewById( R.id.tv_place_adress);

		SQLiteCursor cursor = (SQLiteCursor) getItem(position);
		Log.d("myLogs", cursor.getString(1) + cursor.getString(2));

		Picasso.with(cont).load(cursor.getString(4)).resize(120, 120)
				.centerCrop().into(holder.imageView1);
		holder.textView1.setText(cursor.getString(2));
		holder.textView2.setText(cursor.getString(3));

		return row;
	}

	private class ViewHolder {
		ImageView imageView1;
		TextView textView1;
		TextView textView2;

	}

}
